package cn.tx.controller;


import cn.tx.constant.MessageConstant;
import cn.tx.entity.PageResult;
import cn.tx.entity.QueryPageBean;
import cn.tx.entity.Result;
import cn.tx.pojo.CheckGroup;
import cn.tx.service.CheckGroupService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Snake Eyes
 * @PROJECT_NAME: health_parent
 * @DESCRIPTION:
 * @USER: 11647
 * @DATE: 2021/8/27 12:33
 * @Email: 1164763541@qq.com
 */
@RestController
@RequestMapping("checkgroup")
public class CheckGroupController {

    @Reference
    private CheckGroupService groupService;

    /**
     * @param queryPageBean
     * @return
     * @author :11647
     * @date ：Created in 2021/8/27  14:31
     * @description：(描述) 分页查询
     * @modified By：11647
     * @version:
     */
    @RequestMapping("findPage.do")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult page = groupService.findPage(queryPageBean);
        return new PageResult(page.getTotal(), page.getRows());
    }

    /**
     * @return
     * @author :11647
     * @date ：Created in 2021/8/27  15:32
     * @description：(描述) 查询所有
     * @modified By：11647
     * @version:
     */
    @RequestMapping("findAll.do")
    public Result findAll() {

        try {
            List<CheckGroup> all = groupService.findAll();
            return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS, all);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL);

        }
    }

    /**
     * @param
     * @return
     * @author :11647
     * @date ：Created in 2021/8/27  15:44
     * @description：(描述) 保存方法
     * @modified By：11647
     * @version:
     */

    @RequestMapping("save.do")
    public Result save(Integer[] checkitemIds, @RequestBody CheckGroup formData) {
        try {
            groupService.save(checkitemIds, formData);
            return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ADD_CHECKGROUP_FAIL);
        }
    }

    /**
     * @author :11647
     * @date ：Created in 2021/8/28  15:52
     * @description：(描述) 查询 检查项
     * @modified By：11647
     * @version:
     */
    @RequestMapping("checkItemFindById.do")
    public Result checkItemFindById(Integer checkGroup) {
        try {
            List list = groupService.checkItemFindById(checkGroup);
            return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS, list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL);

        }
    }

    @RequestMapping("update")
    public Result update(Integer[] checkitemIds, @RequestBody CheckGroup formData) {
        try {
            groupService.update(checkitemIds, formData);
            return new Result(true,MessageConstant.EDIT_CHECKGROUP_SUCCESS);

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.EDIT_CHECKGROUP_FAIL);
        }
    }

    @RequestMapping("findDelete.do")
    public Result findDelete(Integer checkGroupId){
        try {
            groupService.delete(checkGroupId);
            return new Result(true,MessageConstant.DELETE_CHECKGROUP_SUCCESS);

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.DELETE_CHECKITEM_FAIL);
        }
    }
}
